package com.itany.corejava.code06_面向对象.封装;

/**
 * @author 石小俊
 * @date 2024年01月16日 9:46
 * 定义一个员工类,包含以下属性与方法
 * 属性: 姓名、工资、性别、年龄
 * 方法: 自我介绍、工作
 * 要求:
 * 1.对属性进行封装,提供赋值与取值方法
 * 2.性别只读,只能看不能改,通过构造方法为性别赋值
 * 3.员工年龄必须大于等于18岁,如果小于18,强制改为18岁
 */
public class Emp {
    private String name;
    private double salary;
    private String gender;
    private int age;

    public Emp(String gender) {
        this.gender = gender;
    }

    public Emp(String name, double salary, String gender, int age) {
        this.name = name;
        this.salary = salary;
        this.gender = gender;
        this.age = age;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public double getSalary() {
        return salary;
    }

    public String getGender() {
        return gender;
    }

    public int getAge() {
        if (age < 18) {
            return 18;
        }
        return age;
    }

    public void show() {
        System.out.println("姓名:" + getName() + ",工资:" + getSalary() + ",性别:" + getGender() + ",年龄:" + getAge());
    }

    public void work() {
        System.out.println(name + "今年" + age + "岁,每天努力996,只为了每月收入" + salary + "元");
    }
}

class Test02 {
    public static void main(String[] args) {
        Emp emp = new Emp("admin", 8000, "男", 15);
        emp.setName("alice");
        emp.setSalary(9000);
        emp.setAge(20);
        emp.show();
    }
}
